package com.redriver.hospitalsystem.systemgetway.swagger;

import org.springframework.stereotype.Component;
import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Component
public class SwaggerConfig implements SwaggerResourcesProvider {

    @Resource
    private swaggerperperties properties;


    @Override
    public List<SwaggerResource> get() {

        List<Swaggers> service = properties.getService();

        List<SwaggerResource> list = new ArrayList();
        for (Swaggers swagger : service) {
            SwaggerResource swaggerResource = create(swagger.getName(), swagger.getUrl());
            list.add(swaggerResource);
        }
        return list;
    }

    private SwaggerResource create(String name,String url) {
        SwaggerResource sr = new SwaggerResource();
        sr.setName(name);
        sr.setUrl(url);
        sr.setSwaggerVersion("2.0");
        return sr;
    }

}
